from launch import LaunchDescription
from launch.conditions import IfCondition
from launch_ros.actions import Node
#封装终端指令相关类--------------
from launch.actions import ExecuteProcess
#from launch.substitutions import FindExecutable
#参数声明与获取-----------------
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
#文件包含相关-------------------
#from launch.actions import IncludeLaunchDescription
#from launch.launch_description_sources import PythonLaunchDescriptionSource
#分组相关----------------------
from launch_ros.actions import PushRosNamespace
from launch.actions import GroupAction
from launch.actions import TimerAction
from launch.actions import LogInfo
#事件相关----------------------
#from launch.event_handlers import OnProcessStart,OnProcessExit
#from launch.actions import ExecuteProcess,RegisterEventHandler,LogInfo
#获取功能包下share目录路径-------
#from ament_index_python.packages import get_package_share_directory

def generate_launch_description():
    rqt=DeclareLaunchArgument("start_rqt",default_value="False")
    start_rqt=LaunchConfiguration("start_rqt")
    
    t1=Node(package="turtlesim",executable="turtlesim_node",name="t1")
    t2=Node(package="turtlesim",executable="turtlesim_node",name="t2")
    t3=Node(package="turtlesim",executable="turtlesim_node",name="t3")
    
    cmd=ExecuteProcess(
        cmd=["rqt"],
        condition=IfCondition(start_rqt)) #如果参数是true执行,否则不执行
    loginfo=LogInfo(msg="++++++++++++")   
      
    #相当于加个命名空间
    g1=GroupAction(actions=[PushRosNamespace("g1"),t1,t2])
    g2=GroupAction(actions=[PushRosNamespace("g2"),t3])
    
    #定时器 period是个浮点参数
    g3=GroupAction([TimerAction(period=5.0,actions=[cmd]),
                    TimerAction(period=10.0,actions=[loginfo])
    ])
    return LaunchDescription([rqt,g1,g2,g3])